package com.five.admin.server.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.five.admin.mapper.AddressMapper;
import com.five.pojo.entity.Address;
import com.five.service.AddressRpcService;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;
import java.util.List;

@DubboService
public class AddressRpcServiceImpl implements AddressRpcService {

    @Resource
    private AddressMapper addressMapper;
    @Override
    public List<Address> queryAddressById(Long id) {
        LambdaQueryWrapper<Address> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Address::getUserId,id);
        return addressMapper.selectList(queryWrapper);
    }

    @Override
    public boolean updateAddressById(Address address) {
        return addressMapper.updateById(address) > 0;
    }

    @Override
    public boolean deleteAddressById(Long id) {
        return addressMapper.deleteById(id) > 0;
    }

    @Override
    public boolean saveAddress(Address address) {
        return addressMapper.insert(address) > 0;
    }

    @Override
    public Address queryOne(Long id) {
        return addressMapper.selectById(id);
    }

    @Override
    public Address findDefaultAddress(Long userId) {
        List<Address> addresses = this.queryAddressById(userId);
        return addresses.get(0);
    }
}
